<template>
    <div class="loading" v-loading="loading" element-loading-text="登录中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)"></div>
</template>

<script>
import { postAdminPricingSetNologin_web } from "@/api";
import { setStore } from "@/utils/localStorage.js";
export default {
    data() {
        return {
            loading: true,
        };
    },
    mounted() {
        let paramArr = window.location.search.replace("?", "").split("&");
        let queryParam = {};
        for(let str of paramArr){
            let param = str.split("=");
            queryParam[param[0]] = param[1];
        }
        //清除地址栏敏感参数 ?code=&state=
        this.$nextTick(() => {
            let url = window.location.href.replace(window.location.search, "")
            window.history.replaceState(null, null, url);
        })
        console.log("query", queryParam);
        // const _GetUrlKey = (name) => {
        //     const reg = new RegExp(`[?|&]${name}=([^&;]+?)(&|#|;|$)`);
        //     const { href } = window.location;
        //     return (
        //         (reg &&
        //             decodeURIComponent(
        //                 (reg.exec(href) || ["", ""])[1].replace(/\+/g, "%20")
        //             )) ||
        //         null
        //     );
        // };
        let obj = {code: queryParam.code, is_subject: queryParam.state};
        postAdminPricingSetNologin_web(obj).then((res) => {
            this.loading = false;
            if(res.code === 0){
                setStore("userinfo", res.data);
                this.$store.commit("mutationsNavMenuList", res.data.roletop);
                let qxobj = {};
                let qx = res.data.roletop[0].list[0].qx;
                qx.forEach((element) => {
                    qxobj[element.rolekey] = 1;
                });
                qxobj = JSON.stringify(qxobj);
                this.$router.push({path: "/home", query: {qxobj}});
            }else{
                this.$message.error(res.msg);
                this.$router.push({path: "/qrCode"});
            }
        }).catch((err) => {
            let data = JSON.stringify(err);
            alert("err" + data + "code:" + queryParam.code);
            this.$router.go(-1);
        });
    },
};
</script>

<style lang="scss" scoped>
.loading {
    width: 100vw;
    height: 100vh;
}
</style>
